package day04;

/**
 * for循环的演示
 */
public class ForDemo {
    public static void main(String[] args) {
        //累加和的案例：1+2+4+8+5.。。100=？
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum = sum + i;
        }
        System.out.println("sum=" + sum);
        /* 执行过程
                       sum=0
            i=1  ture  sum=1
            i=2  true  sum=1+2
            i=3  true  sum=1+2+3
            i=4  true  sum=1+2+3+4
            i=5  true  sum=1+2+3+4+5
            ....
            i=99  true  sum=1+2+3+4....+99
            i=100 true  sum=1+2+3+4....+99+100
            i=101 false 结束循环
         */


        for (int time = 0; time < 9; time++) {
            System.out.println("行动是成功的阶梯");
        }
        System.out.println("继续执行.....");

        for (int num = 9; num >= 1; num--) {
            System.out.println(num + "*9=" + num * 9);
        }
        System.out.println("继续执行.....");

        for (int num = 1; num <= 9; num++) {
            System.out.println(num + "*9=" + num * 9);
        }
        System.out.println("继续执行.....");
        for (int num = 1; num <= 9; num += 2) {
            System.out.println(num + "*9=" + num * 9);
        }
        System.out.println("继续执行.....");

        /*执行过程
        time=1 true 输出 9
        time=3 true 输出 27
        time=5 true 输出 45
        time=7 true 输出 63
        time=9 true 输出 81
        time=11 false 结束
         */

    }
}
